home *** CD-ROM | disk | FTP | other *** search
GW-BASIC | 1997-01-28 | 4.5 KB | 168 lines |
- 10 'CUSTCAP - 09 sep 92 rev. 27 SEP 96 'adapted from CUSTOHM
- 20 IF EX$=""THEN EX$="EXIT"
- 30 IF PROG$=""THEN GO$=EX$ ELSE GO$=PROG$
- 40 COMMON EX$,PROG$
- 50 CLS:KEY OFF
- 60 COLOR 7,0,1
- 70 UL$=STRING$(80,205)
- 80 U$="####,###"
- 90 U1$="##"
- 100 U2$="###,###.##"
- 110 U3$="#####.#"
- 120 U4$="####.#"
- 130 DIM Q(20,3) 'quantity,value,net capacitance
- 140 DIM R(24) '24 combinations
- 150 '.....standard capacitor values
- 160 DATA 1,1.1,1.2,1.3,1.5,1.6,1.8,2.0,2.2,2.4,2.7,3
- 170 DATA 3.3,3.6,3.9,4.3,4.7,5.1,5.6,6.2,6.8,7.5,8.2,9.1
- 180 '.....load data arrays
- 190 FOR Z=1 TO 24
- 200 READ R(Z)
- 210 NEXT Z
- 220 '
- 230 '.....start
- 240 CLS
- 250 COLOR 15,2
- 260 PRINT " CAPACITORS in PARALLEL";TAB(57);"by George Murphy VE3ERP ";
- 270 COLOR 1,0:PRINT STRING$(80,223);
- 280 COLOR 7,0
- 290 T=(8) 'tab for text
- 300 GOSUB 1290 'text
- 310 PRINT
- 320 COLOR 0,7:LOCATE CSRLIN,22
- 330 PRINT " Press 1 to continue or 0 to EXIT....."
- 340 COLOR 7,0
- 350 Z$=INKEY$:IF Z$=""THEN 350
- 360 IF Z$="0"THEN CLS:CHAIN GO$
- 370 IF Z$="1"THEN 410
- 380 GOTO 350
- 390 '
- 400 '.....start
- 410 VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
- 420 PRINT " Press number in < > to select capacitance unit:"
- 430 PRINT UL$;
- 440 PRINT " <1> pF
- 450 PRINT " <2) >F
- 460 PRINT UL$;
- 470 Z$=INKEY$:IF Z$=""THEN 470
- 480 IF Z$="1"THEN O$="pF":GOTO 510
- 490 IF Z$="2"THEN O$=">F":GOTO 510
- 500 GOTO 470
- 510 PRINT " ENTER: Value of custom capacitor (";O$;")";:INPUT RC
- 520 IF RC<1 AND O$=">F"THEN RC=RC*10^6:O$="pF"
- 530 VIEW PRINT 3 TO 24:CLS:VIEW PRINT:LOCATE 3
- 540 '
- 550 '.....calculate capacitor banks
- 560 N=0
- 570 FOR Y=1 TO 10 'no. of capacitors loop
- 580 RX=RC/Y 'value of capacitor
- 590 M=1 'multiplier
- 600 FOR Z=1 TO 24
- 610 IF R(Z)*M>RX THEN 660
- 620 NEXT Z
- 630 M=M*10
- 640 GOTO 600
- 650 '
- 660 R1=R(Z-1)*M 'next lower capacitor
- 670 IF Z=1 THEN R1=R(12)*M/10
- 680 N=N+1 'counter
- 690 Q(N,1)=Y 'quantity of capacitors in bank
- 700 Q(N,2)=R1 'value of each capacitor
- 710 Q(N,3)=R1*Y 'net capacitance of capacitor bank
- 720 '
- 730 R2=R(Z)*M 'next higher capacitor
- 740 N=N+1 'counter
- 750 Q(N,1)=Y 'quantity of capacitors in bank
- 760 Q(N,2)=R2 'value of each capacitor
- 770 Q(N,3)=R2*Y 'net capacitance of capacitor bank
- 780 NEXT Y
- 790 '
- 800 '******START SORT******
- 810 SN=N
- 820 SM=SN
- 830 SM=INT(SM/2):IF SM=0 THEN 920
- 840 SK=SN-SM:SJ=1
- 850 SI=SJ
- 860 SL=SI+SM
- 870 IF Q(SI,3)<=Q(SL,3)THEN 900
- 880 FOR A=1 TO 3:SWAP Q(SI,A),Q(SL,A):NEXT A
- 890 SI=SI-SM:IF SI>0 THEN 860
- 900 SJ=SJ+1:IF SJ>SK THEN 830
- 910 GOTO 850
- 920 '******SORT COMPLETED******
- 930 '
- 940 '....display data
- 950 FOR Z=1 TO N
- 960 PC=ABS(Q(Z,3)-RC)/RC*100 '% off target
- 970 IF Q(Z,1)=1 THEN P$=STRING$(13,32)+"=":ELSE P$=" in parallel ="
- 980 IF Q(Z-1,3)<=RC AND Q(Z,3)>RC THEN GOSUB 1210
- 990 IF PC<=5 THEN COLOR 15,2 ELSE COLOR 7,0
- 1000 PRINT TAB(3);
- 1010 PRINT USING U1$;Q(Z,1); 'print quantity
- 1020 R=Q(Z,2):V$=O$ 'value
- 1030 R$=STR$(R)
- 1040 L$=STR$(LEN(R$)-3)
- 1050 Q$=LEFT$(R$,2)
- 1060 Q$=MID$(R$,3,1)
- 1070 Q$=LEFT$(L$,2)
- 1080 IF R<10 THEN X$=U4$ ELSE X$=U$
- 1090 IF RC<100 THEN U$="######.#"
- 1100 PRINT" @";USING U$;R; 'print value
- 1110 PRINT " ";V$;P$;
- 1120 PRINT USING U2$;Q(Z,3);:PRINT " ";O$; 'print net capacitance of bank
- 1130 IF Q(Z,3)=RC THEN PRINT " ON TARGET ! ":GOTO 1150
- 1140 PRINT USING U3$;PC;:PRINT " % off target" 'discrepancy
- 1150 NEXT Z
- 1160 COLOR 7,0
- 1170 PRINT UL$;
- 1180 GOSUB 1550 'screen dump
- 1190 GOTO 230
- 1200 '
- 1210 '.....hi-lite sought resistance
- 1220 COLOR 14,4
- 1230 PRINT " TARGET CAPACITANCE";
- 1240 PRINT STRING$(13,".");USING U2$;RC;
- 1250 PRINT " ";O$;STRING$(20,32)
- 1260 COLOR 7,0
- 1270 RETURN
- 1280 '
- 1290 '.....text page
- 1300 PRINT TAB(T);
- 1310 PRINT "This program designs custom capacitors that will be very close to"
- 1320 PRINT TAB(T);
- 1330 PRINT "almost any reasonable value, using standard common capacitors"
- 1340 PRINT TAB(T);
- 1350 PRINT "connected in parallel."
- 1360 PRINT
- 1370 PRINT TAB(T);
- 1380 PRINT "The program calculates several combinations of capacitors, any of"
- 1390 PRINT TAB(T);
- 1400 PRINT "which will provide a net capacitance close to your target value."
- 1410 PRINT
- 1420 PRINT TAB(T);
- 1430 PRINT "Each combination displayed shows what percentage it is off the"
- 1440 PRINT TAB(T);
- 1450 PRINT "target capacitance. Combinations within 5% of the target value"
- 1460 PRINT TAB(T);
- 1470 PRINT "are high-lighted."
- 1480 PRINT
- 1490 PRINT TAB(T);
- 1500 PRINT "Just enter the value of the custom capacitor you want and the"
- 1510 PRINT TAB(T);
- 1520 PRINT "computer will do the rest !"
- 1530 RETURN
- 1540 '
- 1550 'HARDCOPY
- 1560 GOSUB 1670:LOCATE 25,2:COLOR 14,6
- 1570 PRINT " Press 1 to print screen, 2 to print screen & ";
- 1580 PRINT "advance paper, or 3 to continue.";:COLOR 7,0
- 1590 Z$=INKEY$:IF Z$="3"THEN GOSUB 1670:RETURN
- 1600 IF Z$="1"OR Z$="2"THEN GOSUB 1670:GOTO 1620
- 1610 GOTO 1590
- 1620 FOR QX=1 TO 24:FOR QY=1 TO 80
- 1630 LPRINT CHR$(SCREEN(QX,QY));
- 1640 NEXT QY:NEXT QX
- 1650 IF Z$="2"THEN LPRINT CHR$(12)
- 1660 GOTO 1560
- 1670 LOCATE 25,1:PRINT STRING$(80,32);:RETURN
-